#!/bin/bash

# Copyright (C) 2010, 2011, 2012, 2013 Embecosm Limited

# Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
# Contributor Joern Rennecke <joern.rennecke@embecosm.com>

# This file is additional DejaGnu procs to support telnet based testing.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.

# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.

#		   ARC Linux DejaGnu Generic Board Support
#		   =======================================

# This is the generic board setup for all ARC Linux ports. It is loaded by the
# boards specific to particular systems. It should not be used directly.

# This is a list of toolchains that are supported on this board.
set_board_info target_install ${target_triplet}

# Load the generic configuration for this board. This will define a basic set
# of routines needed by the tool to communicate with the board. Depends on the
# tool.
if { $tool == "gdb" } {
    load_generic_config "gdbserver"
} else {
    load_generic_config "unix"
}

# We need some extra and modified procs for testing with telnet, FTP and
# gdbserver.
search_and_load_file "library file" "telnet-extra.exp" ${boards_dir}
search_and_load_file "library file" "ftp-extra.exp" ${boards_dir}
search_and_load_file "library file" "gdb-extra.exp" ${boards_dir}

# No multilib options needed by default.
process_multilib_options ""

# Specify the compilers to use.
set_board_info compiler [find_gcc]

# Set up connection using telnet and FTP. Hostname, prompts, usernames and
# passwords are in the board specific files.
set_board_info connect        telnet
set_board_info file_transfer  ftp

# We only support newlib on this target. We assume that all multilib
# options have been specified before we get here.

# We need to define this flag to generate default .gcda files if we are using
# a stock compiler, without the profopt.exp changes. No problem with doubling
# up the argument in normal circumstances.
set_board_info cflags    "-fprofile-dir=."
set_board_info cxxflags  "-fprofile-dir=."

# No linker script needed.
set_board_info ldscript ""

# Can't pass arguments to programs on this target..
set_board_info noargs  1

# Used by a few gcc.c-torture testcases to delimit how large the stack can
# be.
set_board_info gcc,stack_size 65536

# GDB options

# We can't do input in GDB (yet! HA!). It *will* do output, hurrah.
set_board_info gdb,noinferiorio 1
# Or pass arguments.
set_board_info gdb,noargs  1
# And there's no support for signals.
set_board_info gdb,nosignals  1
# GDB can't return results
set_board_info gdb,noresults 1

if { $tool == "gdb" } {
    # GDB specific setup to enable gdbserver on the target.

    # Use telnet as protocol to spawn gdbserver
    set_board_info protocol telnet
    # Standard remote serial protocol
    set_board_info gdb_protocol "remote"
    # We can only run one program at a time
    set_board_info gdb,do_reload_on_run 1
    # No hardware watchpoints
    set_board_info gdb,no_hardware_watchpoints 1
    # The command to use
    set_board_info gdb_server_prog /bin/gdbserver
    # Use a GDB stub
    set_board_info use_gdb_stub 1

    # Set up sysroot. This is an option relating to the host running GDB, not
    # the board, hence the contortion.
    set board_info([get_local_hostname],gdb_opts) "-x $env(ARC_GDB_COMMFILE)"
}
